package com.example.mobile2021606176mhq0509;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;

public class PartActivity extends AppCompatActivity {

    private TextView tvPartTitle;
    private RadioGroup radgroup;
    private RadioButton rdbtnMainYingqing;
    private RadioButton rdbtnMainQianboli;
    private RadioButton rdbtnMainLuntai;
    private RadioButton rdbtnMainDipan;
    private RadioButton rdbtnQiangai;
    private RadioButton rdbtnXuanGua;
    private RadioButton radbtnZuoYi;
    private RadioButton radbtnFangXiangPan;
    private RadioButton radbtnCheJia;
    private RadioButton radbtnCheMen;
    private RadioButton radbtnHouBoLI;
    private Button btnPartAdd;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_part);
        initView();
        btnPartAdd.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int radBtnId = radgroup.getCheckedRadioButtonId();
                if (radBtnId != -1) {
                    RadioButton radioButton = findViewById(radBtnId);
                    Intent intent = new Intent();
                    intent.putExtra("Part", radioButton.getText().toString());
                    setResult(RESULT_OK, intent);
                    finish();
                } else {
                    new AlertDialog.Builder(PartActivity.this)
                            .setMessage("请选择原材料商")
                            .setPositiveButton("确定", null)
                            .create()
                            .show();

                }
            }
        });
    }

    private void initView() {
        tvPartTitle = (TextView) findViewById(R.id.tvPartTitle);
        radgroup = (RadioGroup) findViewById(R.id.radgroup);
        rdbtnMainYingqing = (RadioButton) findViewById(R.id.rdbtnMainYingqing);
        rdbtnMainQianboli = (RadioButton) findViewById(R.id.rdbtnMainQianboli);
        rdbtnMainLuntai = (RadioButton) findViewById(R.id.rdbtnMainLuntai);
        rdbtnMainDipan = (RadioButton) findViewById(R.id.rdbtnMainDipan);
        rdbtnQiangai = (RadioButton) findViewById(R.id.rdbtnQiangai);
        rdbtnXuanGua = (RadioButton) findViewById(R.id.rdbtnXuanGua);
        radbtnZuoYi = (RadioButton) findViewById(R.id.radbtnZuoYi);
        radbtnFangXiangPan = (RadioButton) findViewById(R.id.radbtnFangXiangPan);
        radbtnCheJia = (RadioButton) findViewById(R.id.radbtnCheJia);
        radbtnCheMen = (RadioButton) findViewById(R.id.radbtnCheMen);
        radbtnHouBoLI = (RadioButton) findViewById(R.id.radbtnHouBoLI);
        btnPartAdd = (Button) findViewById(R.id.btnPartAdd);
    }
}